/*
 * Public Credit Information Sharing Platform(PCISP).
 * Copyright (c) 2019-2020 jsxzkingdee and/or its affiliates. All rights reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 * Please visit https://www.zhengxinsoft.com if you need additional information or have any questions.
 */

package com.platform.core.limit;

import com.platform.comm.exceptions.RestApiException;
import com.platform.core.limit.filter.BloomCacheFilter;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

/**
 * Description: com.platform.core.limit
 *
 * @author libin created on 2020/5/8.
 */
@Aspect
@Component
public class BloomAspect {

    /**
     * 切点  限流
     */
    @Pointcut("@annotation(com.platform.core.limit.BloomLimit) && args(id)")
    public void bloomAspect(String id) {

    }

    @Before(value = "bloomAspect(id)", argNames = "id")
    public void around(String id) {
        try {
            if (BloomCacheFilter.mightContain(Long.parseLong(id))) {
            } else {
                throw new RestApiException("你访问的内容不存在");
            }
        } catch (Throwable e) {
            throw new RestApiException("你访问的内容不存在");
        }
    }
}
